home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / linkedit / linkedit.lha / link-edit / LinkEdit / Box / box_bp.c next >
Encoding:
C/C++ Source or Header  |  1991-03-13  |  8.1 KB  |  325 lines

  1. #include <stdio.h>
  2. #include <X11/Xlib.h>
  3. #include "box_types.h"
  4. #include "box_global.h"
  5.  
  6.  
  7. BoxButtonPress(gnrc,event)
  8.  
  9. BoxStatus *gnrc;
  10. XEvent *event;
  11.  
  12. {
  13.   BoxList *bx;
  14.   int x,y,x1,y1;
  15.   XEvent evnt;
  16.  
  17.   x = event->xbutton.x;
  18.   y = event->xbutton.y;
  19.  
  20.   bx = FindBoxByPosition(gnrc,x,y);
  21.  
  22.   /* Check if valid choice of box */
  23.   if(bx == &(gnrc->box)) {
  24.     switch(gnrc->current_box->type) {
  25.  
  26.        case BOX_MENU:  /* Ok to erase display to initial setting */
  27.          BoxReset(gnrc); 
  28.          break;
  29.  
  30.        default: /* better not do anything drastic */
  31.          BoxPrintMessage(gnrc,"Current selection must be completed.");
  32.          break;
  33.       }
  34.     return(-1); 
  35.    }
  36.  
  37.   /* modify sliders-  need to use x,y coordinates */
  38.   /* Probably better to use XQueryPointer and do this in BoxSelect */
  39.   switch(bx->type) {
  40.       
  41.      case BOX_HORIZONTAL_SLIDER:
  42.        BoxPrintMessage(gnrc,"Slider Chosen.");
  43.        gnrc->current_box = bx;
  44.        /* Compute new value */
  45.        bx ->value = (double) (x - bx->x) / (double) bx->width;
  46.        DrawBox(gnrc,bx);
  47.        break;
  48.  
  49.      case BOX_VERTICAL_SLIDER:
  50.        BoxPrintMessage(gnrc,"Slider Chosen.");
  51.        gnrc->current_box = bx;
  52.        /* Compute new value */
  53.        bx ->value = 1.0 - (double) (y - bx->y) / (double) bx->height;
  54.        DrawBox(gnrc,bx);
  55.        break;
  56.     }
  57.   /* Do continuous callbacks */
  58.   switch(bx->type) {  /* Text entry is special */
  59.  
  60.      case BOX_TEXT_ENTRY:
  61.        break;
  62.  
  63.      default:
  64.        if(bx->continuous_local_callback != NULL ||
  65.                  bx->continuous_global_callback != NULL) {
  66.           while(1) {
  67.  
  68.               if(XCheckMaskEvent(dpy,ButtonReleaseMask,&evnt)) break;
  69.  
  70.               if(bx->continuous_local_callback != NULL) {
  71.                     (*(bx->continuous_local_callback))(gnrc,bx);
  72.                 }
  73.               if(bx->continuous_global_callback != NULL) {
  74.                  if(bx->global_arg != NULL)
  75.                     (*(bx->continuous_global_callback))(bx->global_arg,
  76.                                              (VOID *)gnrc,bx->id);
  77.  
  78.                  else
  79.                     (*(bx->continuous_global_callback))(gnrc->arg,(VOID *)gnrc,
  80.                                              bx->id);
  81.                 }
  82.              }
  83.           }
  84.         break;
  85.      }
  86.   /* React to being selected */
  87.   BoxSelect(gnrc,bx);
  88. }
  89.  
  90. BoxCleanup(gnrc,bx)
  91.  
  92. BoxStatus *gnrc;
  93. BoxList *bx;
  94.  
  95. /* Routine cleans up the display after a box with the cleanup flag is */
  96. /* activated.  The cleanup goes to the top level or until a box with */
  97. /* the stop cleanup flag is set */
  98.  
  99. {
  100.   BoxList *parent,*child;
  101.  
  102.      parent = bx->parent;
  103.      if(bx->always_visible == BOX_YES || parent == &(gnrc->box)) { 
  104.         /* No serious cleanup necessary */
  105.         BoxCleanupState(gnrc,bx);
  106.         DrawBox(gnrc,bx);
  107.         gnrc->current_box = &(gnrc->box);
  108.         return(0);
  109.        }
  110.      while(parent->parent != &(gnrc->box) && parent->stop_cleanup != BOX_YES) { 
  111.         parent->visible = BOX_NO;
  112.         BoxCleanupState(gnrc,parent);
  113.         child = parent->child;
  114.         while(child != NULL) {
  115.            child->visible = BOX_NO; 
  116.            BoxCleanupState(gnrc,child);
  117.            DrawBox(gnrc,child);
  118.            child = child->sibling;
  119.           }
  120.         DrawBox(gnrc,parent);
  121.         parent = parent->parent;
  122.        }
  123.      BoxCleanupState(gnrc,parent);
  124.      child = parent->child;  /* children of last parent missed above */
  125.      while(child != NULL) {
  126.         child->visible = BOX_NO; 
  127.         BoxCleanupState(gnrc,child);
  128.         DrawBox(gnrc,child);
  129.         child = child->sibling;
  130.        }
  131.  
  132.      gnrc->current_box = parent->parent;
  133.      XClearWindow(dpy,gnrc->TopWindow);
  134.      ReDrawBoxTopWindow(gnrc);
  135. }
  136.  
  137. BoxCleanupState(gnrc,bx)
  138.  
  139. BoxStatus *gnrc;
  140. BoxList *bx;     /* What to do with a box's state on cleanup */
  141.  
  142. {
  143.   switch(bx->type) {
  144.      case BOX_MENU:
  145.      case BOX_TEXT_ENTRY:
  146.        bx->state = BOX_NO;
  147.        break;
  148.     }
  149. }
  150.  
  151. BoxFlashTime()
  152.  
  153. {
  154.   int i;
  155.   for(i=0;i<BOX_FLASH_COUNT;++i);
  156. }
  157.  
  158. BoxIsValidChoice(gnrc,bx)
  159.  
  160. BoxStatus *gnrc;
  161. BoxList *bx;
  162.  
  163. {
  164.   int valid;
  165.   valid = 1;
  166.   switch(gnrc->current_box->type) {
  167.      case BOX_MENU:
  168.        if(!BoxIsADescendent(gnrc,bx,gnrc->current_box)) valid = 0;
  169.        break;
  170.      case BOX_TOGGLE:
  171.      case BOX_TEXT_ENTRY:
  172.      case BOX_HORIZONTAL_SLIDER:
  173.      case BOX_VERTICAL_SLIDER:
  174.        if(!BoxIsADescendent(gnrc,bx,gnrc->current_box)
  175.              && !BoxIsASibling(gnrc,bx,gnrc->current_box))  valid = 0;
  176.        break;
  177.     }
  178.  
  179.   return(valid);
  180. }
  181.  
  182. BoxSelect(gnrc,bx)
  183.  
  184. BoxStatus *gnrc;
  185. BoxList *bx;
  186.  
  187. /* How a box reacts to being selected.  Note that slider repositioning */
  188. /* must occur prior to this call */
  189. /* Also, continuous callbacks, since they involve mouse or key events */
  190. {
  191.   BoxList *child,*parent;
  192.  
  193.   switch(bx->type) {
  194.       
  195.      case BOX_MENU:
  196.        BoxPrintMessage(gnrc,"Menu Chosen.");
  197.        gnrc->current_box = bx;
  198.        bx->state = BOX_YES;
  199.        DrawBox(gnrc,bx);
  200.        /* if last menu in cascade just flash it */
  201.        if(bx->child == NULL) {
  202.           BoxFlashTime();
  203.           bx->state = BOX_NO; DrawBox(gnrc,bx);
  204.          }
  205.        break;
  206.  
  207.      case BOX_TOGGLE:
  208.        BoxPrintMessage(gnrc,"Toggle Chosen.");
  209.        if(BoxIsASibling(gnrc,bx,gnrc->current_box) &&
  210.                    gnrc->current_box->type != BOX_TOGGLE) {
  211.           gnrc->current_box->state = BOX_NO;
  212.           DrawBox(gnrc,gnrc->current_box);
  213.          }
  214.        gnrc->current_box = bx;
  215.        if(bx->state == BOX_YES) { bx->state = BOX_NO; DrawBox(gnrc,bx); }
  216.        else {
  217.           bx->state = BOX_YES; DrawBox(gnrc,bx);
  218.           /* check exclusive flag of parent */
  219.           parent = bx->parent;
  220.           if(parent->exclusive == BOX_YES) {
  221.              child = parent->child;
  222.              while(child != NULL) {
  223.                  if(child->state == BOX_YES && child != bx && 
  224.                       child->type == BOX_TOGGLE) {
  225.                     child->state = BOX_NO; DrawBox(gnrc,child);
  226.                    }
  227.                  child = child->sibling;
  228.                 }
  229.             }
  230.          }
  231.        break;
  232.  
  233.      case BOX_TEXT_ENTRY:
  234.        BoxPrintMessage(gnrc,"Text Entry Chosen.");
  235.        if(BoxIsASibling(gnrc,bx,gnrc->current_box) &&
  236.                    gnrc->current_box->type != BOX_TOGGLE) {
  237.           gnrc->current_box->state = BOX_NO;
  238.           DrawBox(gnrc,gnrc->current_box);
  239.          }
  240.        gnrc->current_box = bx; 
  241.        bx->state = BOX_YES; DrawBox(gnrc,bx);
  242.        break;
  243.  
  244.      case BOX_HORIZONTAL_SLIDER:
  245.      case BOX_VERTICAL_SLIDER:
  246.        break;
  247.  
  248.      default:
  249.        fprintf(stderr,"Unknown type of box.\n");
  250.        break;
  251.     }
  252.   /* Do callbacks : note text entry callbacks done on 'return'*/
  253.   switch(bx->type) {
  254.  
  255.     case BOX_TEXT_ENTRY:
  256.       break;
  257.  
  258.     default:
  259.  
  260.       if(bx->local_callback != NULL) {
  261.          (*(bx->local_callback))(gnrc,bx);
  262.         }
  263.       if(bx->global_callback != NULL) {
  264.          /* if bx has global_arg use it, otherwise use gnrc->arg */
  265.          if(bx->global_arg != NULL) {
  266.             (*(bx->global_callback))(bx->global_arg,(VOID *)gnrc,bx->id);
  267.            }
  268.          else {
  269.             (*(bx->global_callback))(gnrc->arg,(VOID *)gnrc,bx->id);
  270.            }
  271.         }
  272.  
  273.       break;
  274.     }
  275.   /* Post selection processing */
  276.  
  277.   switch(bx->type) {
  278.      case BOX_TOGGLE:
  279.      case BOX_MENU:
  280.      case BOX_HORIZONTAL_SLIDER:
  281.      case BOX_VERTICAL_SLIDER:
  282.        /* draw children */
  283.        child = bx->child;
  284.        while(child != NULL) {
  285.           child->visible = BOX_YES; DrawBox(gnrc,child);
  286.           child = child->sibling;
  287.          }
  288.  
  289.        if(bx->induce_state_change == BOX_YES) {
  290.           gnrc->state_change = BOX_YES;
  291.           gnrc->select_box = bx;
  292.          }
  293.        if(bx->cleanup == BOX_YES)  BoxCleanup(gnrc,bx);
  294.        break;
  295.  
  296.      case BOX_TEXT_ENTRY:
  297.        /* This is done within the BoxTextEntryKey routine when 'return' */
  298.        /* is pressed */
  299.        break;
  300.     }
  301. }
  302.  
  303. BoxReset(gnrc)
  304.  
  305. BoxStatus *gnrc;
  306.  
  307. {
  308.   BoxList *bx;
  309.  
  310.   gnrc->current_box = &(gnrc->box);
  311.   bx = gnrc->box.next;
  312.   while(bx != NULL) {
  313.      if(bx->parent != &(gnrc->box)) bx->visible = BOX_NO;
  314.      switch(bx->type) {
  315.         case BOX_MENU:
  316.           bx->state = BOX_NO;
  317.           break;
  318.        }
  319.      bx = bx->next;
  320.     }
  321.   XClearWindow(dpy,gnrc->TopWindow);
  322.   ReDrawBoxTopWindow(gnrc);
  323. }
  324.  
  325.